package com.pano.controal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.pano.Enum.ResultMessage;
import com.pano.entity.Vpoi;
import com.pano.service.VpoiService;

@RestController
@RequestMapping("/vpoi")
@SuppressWarnings("all")
public class VpoiController extends BaseController {

	@Autowired
	private VpoiService vpoiService;

	/***
	 * 全景列表
	 * @return
	 */
	@RequestMapping(path = { "/search" }, method = { RequestMethod.POST })
	public Map searchVpoi() {
		Map map = new HashMap();
		List rows = vpoiService.findAll();
		map.put("rows", rows);
		return map;
	}

	/***
	 * 创建全景
	 * @param vpoi
	 * @return
	 */
	@RequestMapping(path = { "/create" }, method = {  RequestMethod.POST })
	public Map createVpoi(@ModelAttribute("vpoi") Vpoi vpoi) {
		try {
			vpoiService.save(vpoi);
		} catch (Exception e) {
			return returnMap(ResultMessage.ADD_ERROR);
		}
		return returnMap(ResultMessage.ADD_SUCCESS);
	}
	
	/***
	 * 修改全景部分属性
	 * @param vpoi
	 * @return
	 */
	@RequestMapping(path = { "/update" }, method = { RequestMethod.POST })
	public Map updateVpoi(@ModelAttribute("vpoi") Vpoi vpoi) {
		try {
			vpoiService.update(vpoi);
		} catch (Exception e) {
			return returnMap(ResultMessage.UPDATE_ERROR);
		}
		return returnMap(ResultMessage.UPDATE_SUCCESS);
	}
	
	/***
	 * 移除全景
	 * @param id
	 * @return
	 */
	@RequestMapping(path = { "/remove/{id}" }, method = { RequestMethod.GET, RequestMethod.POST })
	public Map removeVpoi(@PathVariable int id) {
		try {
			vpoiService.delete(id);
		} catch (Exception e) {
			return returnMap(ResultMessage.REMOVE_ERROR);
		}
		return returnMap(ResultMessage.REMOVE_SUCCESS);
	}
}
